﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.TownshipEnterprise.Model;
using Yipusoft.TownshipEnterprise.BLL;
using Yipusoft.Common.BLL;

public partial class TownshipEnterprise_DeviceView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "200500") && !Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "200508"))
            {
                Response.Write("<script>alert('没有权限！');window.close();</script>");
                return;
            }
            ActionTitle.Text = "查看装备器材";
            BindData();
            //BindGrid();
        }
    }
    private void BindData()
    {
        TownDevicesInfo device = TownDevices.GetTownDevices(new Guid(Request.QueryString["DeviceID"]));
        TownBasicID.Text = TownBasic.GetTownBasic(new Guid(device.TownBasicID)).Army;
        if (device.DeviceClass != "")
        {
            DeviceClass.Text = CodeItem.GetCodeItem(device.DeviceClass).ItemName;
        }
        DeviceName.Text = device.DeviceName;
        DeviceModel.Text = device.DeviceModel;
        DeviceCount.Text = device.DeviceCount.ToString() + CodeItem.GetCodeItem(device.UnitName).ItemName;
        Parameters.Text = device.Parameters;
        Price.Text = device.Price.ToString();
        DatePurchase.Text = device.DatePurchase.Year == 9999 ? "" : device.DatePurchase.ToLongDateString();
        DateUse.Text = device.DateUse.Year == 9999 ? "" : device.DateUse.ToLongDateString();
        DateProduct.Text = device.DateProduct.Year == 9999 ? "" : device.DateProduct.ToLongDateString();
        Manufacturer.Text = device.Manufacturer;
        State.Text = CodeItem.GetCodeItem(device.State).ItemName;
        if (device.Picture != "")
        {
            Picture.Text = "<a href=" + device.Picture + " target=_blank title=点击查看原图><img src='../TownshipEnterprise/" + device.Picture + "' width='480px' /></a>";
        }
    }
    private void BindGrid()
    {
        //List<AttachmentInfo> atta = Attachment.GetList("ItemID='" + Request.QueryString["DeviceID"] + "'");

        //UserGrid.DataSource = atta;
        //UserGrid.DataBind();
    }
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
}
